package com.crm.suborgConfig.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.crm.suborgConfig.mapper.BaseSuborgConfigMapper;
import com.crm.suborgConfig.domain.BaseSuborgConfig;
import com.crm.suborgConfig.service.IBaseSuborgConfigService;

/**
 * 分公司配置Service业务层处理
 *
 * @author ruoyi
 * @date 2024-01-29
 */
@Service
public class BaseSuborgConfigServiceImpl implements IBaseSuborgConfigService {
    @Autowired
    private BaseSuborgConfigMapper baseSuborgConfigMapper;

    /**
     * 查询分公司配置
     *
     * @param orgId 分公司配置主键
     * @return 分公司配置
     */
    @Override
    public BaseSuborgConfig selectBaseSuborgConfigByOrgId(Long orgId) {
        return baseSuborgConfigMapper.selectBaseSuborgConfigByOrgId(orgId);
    }

    /**
     * 查询分公司配置列表
     *
     * @param baseSuborgConfig 分公司配置
     * @return 分公司配置
     */
    @Override
    public List<BaseSuborgConfig> selectBaseSuborgConfigList(BaseSuborgConfig baseSuborgConfig) {
        return baseSuborgConfigMapper.selectBaseSuborgConfigList(baseSuborgConfig);
    }

    /**
     * 新增分公司配置
     *
     * @param baseSuborgConfig 分公司配置
     * @return 结果
     */
    @Override
    public int insertBaseSuborgConfig(BaseSuborgConfig baseSuborgConfig) {
        baseSuborgConfig.setCreateTime(DateUtils.getNowDate());
        return baseSuborgConfigMapper.insertBaseSuborgConfig(baseSuborgConfig);
    }

    /**
     * 修改分公司配置
     *
     * @param baseSuborgConfig 分公司配置
     * @return 结果
     */
    @Override
    public int updateBaseSuborgConfig(BaseSuborgConfig baseSuborgConfig) {
        return baseSuborgConfigMapper.updateBaseSuborgConfig(baseSuborgConfig);
    }

    /**
     * 批量删除分公司配置
     *
     * @param orgIds 需要删除的分公司配置主键
     * @return 结果
     */
    @Override
    public int deleteBaseSuborgConfigByOrgIds(Long[] orgIds) {
        return baseSuborgConfigMapper.deleteBaseSuborgConfigByOrgIds(orgIds);
    }

    /**
     * 删除分公司配置信息
     *
     * @param orgId 分公司配置主键
     * @return 结果
     */
    @Override
    public int deleteBaseSuborgConfigByOrgId(Long orgId) {
        return baseSuborgConfigMapper.deleteBaseSuborgConfigByOrgId(orgId);
    }

    /**
     * 根据城市查找总公司
     *
     * @param cityName
     * @return
     */
    @Override
    public List<BaseSuborgConfig> getByCity(String cityName) {
        BaseSuborgConfig baseSuborgConfig = new BaseSuborgConfig();
        baseSuborgConfig.setCity(cityName);
        return baseSuborgConfigMapper.selectBaseSuborgConfigList(baseSuborgConfig);
    }
    /**
     * 获取城市信息
     * @return
     */
    @Override
    public List<String> getAllCitys(){
        List<String> cities = new ArrayList<>();
        List<BaseSuborgConfig> listBase=baseSuborgConfigMapper.selectBaseSuborgConfigList(new BaseSuborgConfig());
        for (BaseSuborgConfig baseSuborgConfig : listBase) {
            cities.add(baseSuborgConfig.getCity());
        }
        return cities;
    }
}
